﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using Microsoft.Win32;


namespace Setup.CustomActions
{
    [RunInstaller(true)]
    public partial class CustomInstaller : System.Configuration.Install.Installer
    {
        public CustomInstaller()
        {
            InitializeComponent();
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            System.Diagnostics.Process.Start("http://www.microsoft.com");
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {

            int processId = System.Diagnostics.Process.GetCurrentProcess().Id;
            string message = string.Format("Please attach the debugger (elevated on Vista or Win 7) to process [{0}].", processId);
            System.Windows.Forms.MessageBox.Show(message, "Debug");

            
            base.Uninstall(savedState);

            //string keyName1 = @"Software\Microsoft\Office\FormRegions\IPM.Appointment";
            //string keyName2 = @"Software\Microsoft\Office\FormRegions\IPM.Schedule.Meeting.Request";

            //using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName1, true))
            //{
            //    System.Windows.Forms.MessageBox.Show(key.Name);
            //    if (key != null)
            //    {

            //        key.DeleteValue("AFS.VisitationRequestTool.Addin.Components.RequestDetailsFormRegion");
            //    }
            //}

            //using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName2, true))
            //{
            //    if (key != null)
            //    {
            //        key.DeleteValue("AFS.VisitationRequestTool.Addin.Components.RequestDetailsFormRegion");
            //    }
            //}

            //System.Diagnostics.Debug.WriteLine("Addin Uninstalled");
        }


    }
}
